package com.aps.apspda.activity;

import android.os.Handler;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.aps.apspda.R;
import com.aps.apspda.adapter.EqpThingListAdapter;
import com.aps.apspda.adapter.InputDataListAdapter;
import com.aps.apspda.base.BaseActivity;
import com.aps.apspda.callback.DialogEntityCallBack;
import com.aps.apspda.callback.EntityCallBack;
import com.aps.apspda.entity.BaseEntity;
import com.aps.apspda.entity.ChangeThingInputDataEntity;
import com.aps.apspda.entity.InputDataEntity;
import com.aps.apspda.entity.MaterialInfoBean;
import com.aps.apspda.entity.WaferSawEntity;
import com.aps.apspda.myview.ClearEditText;
import com.aps.apspda.myview.TitleView;
import com.aps.apspda.utils.AntiShake;
import com.aps.apspda.utils.NetUtils;
import com.aps.apspda.utils.StaticMembers;
import com.aps.apspda.utils.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

public class BothThingChangeActivity extends BaseActivity {

    @BindView(R.id.topView)
    TitleView topView;
    @BindView(R.id.tvEqpId)
    TextView tvEqpId;
    @BindView(R.id.etInput1)
    ClearEditText etInput1;
    @BindView(R.id.rvEqpList1)
    RecyclerView rvEqpList1;
    @BindView(R.id.rvInputDataList1)
    RecyclerView rvInputDataList1;
    @BindView(R.id.etInput2)
    ClearEditText etInput2;
    @BindView(R.id.rvEqpList2)
    RecyclerView rvEqpList2;
    @BindView(R.id.rvInputDataList2)
    RecyclerView rvInputDataList2;
    @BindView(R.id.tvTitle1)
    TextView tvTitle1;
    @BindView(R.id.tvTitle2)
    TextView tvTitle2;


    private List<MaterialInfoBean> materialinfoBeanList1, materialinfoBeanList2;
    private EqpThingListAdapter eqpThingListAdapter1, eqpThingListAdapter2;
    private MaterialInfoBean bean1, bean2;
    private String type1, type2;
    private boolean isAllow1 = false;
    private boolean isYingYuan1 = false;
    private boolean isAllow2 = false;
    private boolean isYingYuan2 = false;
    private List<InputDataEntity.InputObject> inputList1, inputList2;
    private int successCount = 0;
    private int numIs;
    @Override
    protected int getLayoutResId() {
        return R.layout.activity_both_thing_change;
    }

    @Override
    protected void initView() {
        topView.setTitle("材料更换(" + StaticMembers.CUR_USER.getUSERNAME() + ")");
        topView.setTitleMode(TitleView.NORMAL_TEXT_MODE);
        topView.setRightListener("确定更换", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (AntiShake.check(v.getId())) {    //判断是否多次点击
                    ToastUtils.showFreeToast("请勿重复点击",
                            BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                    return;
                }
                if (materialinfoBeanList1.size() == 0) {
                    ToastUtils.showFreeToast("请先扫描物料" + tvTitle1.getText(),
                            BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                    return;
                }
                if (materialinfoBeanList2.size() == 0) {
                    ToastUtils.showFreeToast("请先扫描物料" + tvTitle2.getText(),
                            BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                    return;
                }
                if (isAllow1) {
                    boolean isOk1 = true;
                    for (InputDataEntity.InputObject inputObject : inputList1) {
                        if (inputObject.getISNULL().equalsIgnoreCase("Y")) {
                            if (inputObject.getDATAVALUE().length() == 0) {
                                isOk1 = false;
                                ToastUtils.showFreeToast("请填写物料" + tvTitle1.getText() + "带*栏数据", BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                                break;
                            } else {
                                if (inputObject.getDATAVALUE().toUpperCase().contains("NG")) {
                                    String[] strs = inputObject.getDATAVALUE().split(";");
                                    if (strs.length <= 1) {
                                        isOk1 = false;
                                        ToastUtils.showFreeToast("请给物料" + tvTitle1.getText() + "NG项填写原因", BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                                    }
                                }
                            }
                        }
                    }
                    if (isOk1) {
                        if (isAllow2) {
                            boolean isOk2 = true;
                            for (InputDataEntity.InputObject inputObject : inputList2) {
                                if (inputObject.getISNULL().equalsIgnoreCase("Y")) {
                                    if (inputObject.getDATAVALUE().length() == 0) {
                                        isOk2 = false;
                                        ToastUtils.showFreeToast("请填写物料" + tvTitle2.getText() + "带*栏数据", BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                                        break;
                                    } else {
                                        if (inputObject.getDATAVALUE().toUpperCase().contains("NG")) {
                                            String[] strs = inputObject.getDATAVALUE().split(";");
                                            if (strs.length <= 1) {
                                                isOk2 = false;
                                                ToastUtils.showFreeToast("请给物料" + tvTitle2.getText() + "NG项填写原因", BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                                            }
                                        }
                                    }
                                }
                            }
                            if (isOk2) {
                                requestSubmit("change", 1);
                                requestSubmit("change", 2);
                            }
                        } else {
                            ToastUtils.showFreeToast("请检查扫描的物料条码" + tvTitle2.getText() + "是否正确",
                                    BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                        }
                    }
                } else {
                    ToastUtils.showFreeToast("请检查扫描的物料条码" + tvTitle1.getText() + "是否正确",
                            BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                }
            }
        });
        rvEqpList1.setLayoutManager(new LinearLayoutManager(BothThingChangeActivity.this));
        rvEqpList1.setItemAnimator(new DefaultItemAnimator());
        rvEqpList1.addItemDecoration(new DividerItemDecoration(BothThingChangeActivity.this, 1));
        rvInputDataList1.setLayoutManager(new LinearLayoutManager(BothThingChangeActivity.this));
        rvInputDataList1.setItemAnimator(new DefaultItemAnimator());
        rvInputDataList1.addItemDecoration(new DividerItemDecoration(BothThingChangeActivity.this, 1));
        rvEqpList2.setLayoutManager(new LinearLayoutManager(BothThingChangeActivity.this));
        rvEqpList2.setItemAnimator(new DefaultItemAnimator());
        rvEqpList2.addItemDecoration(new DividerItemDecoration(BothThingChangeActivity.this, 1));
        rvInputDataList2.setLayoutManager(new LinearLayoutManager(BothThingChangeActivity.this));
        rvInputDataList2.setItemAnimator(new DefaultItemAnimator());
        rvInputDataList2.addItemDecoration(new DividerItemDecoration(BothThingChangeActivity.this, 1));
        bean1 = (MaterialInfoBean)
                getIntent().getSerializableExtra("mEntity1");
        type1 = bean1.getType();
        bean2 = (MaterialInfoBean)
                getIntent().getSerializableExtra("mEntity2");
        type2 = bean2.getType();
        tvTitle1.setText(bean1.getType().equals("HubBladeYZ1") ? "Z1" : "Z2");
        tvTitle2.setText(bean2.getType().equals("HubBladeYZ1") ? "Z1" : "Z2");
        tvEqpId.setText(getEqpID());
        setCallback(etInput2);
        etInput1.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((keyCode == 138 || keyCode == 240 || keyCode == 241 || keyCode == 242) && etInput1 != null && event.getAction() == KeyEvent.ACTION_DOWN) {
                    etInput1.setText("");
                    etInput1.requestFocus();
                    return true;
                }
                return false;
            }
        });
        etInput1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                return event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER);
            }
        });

        etInput1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    if (s.length() > 0) {
                        //扫描到数据 然后请求接口
                        isAllow1 = isAllow(s.toString(), 1);
                        if (type1.equals("HubBlade") || type1.equals("HubBladeYZ1") || type1.equals("HubBladeYZ2")) {
                            if (!isYingYuan1) {
                                if (isAllow1) {
                                    materialinfoBeanList1.clear();
                                    materialinfoBeanList1.add(bean1);
                                    eqpThingListAdapter1.notifyDataSetChanged();
                                    requestSubmit("check", 1);
                                    rvInputDataList1.setVisibility(View.VISIBLE);
                                } else {
                                    materialinfoBeanList1.clear();
                                    eqpThingListAdapter1.notifyDataSetChanged();
                                    rvInputDataList1.setVisibility(View.GONE);
                                    ToastUtils.showFreeToast("请检查扫描的物料条码" + tvTitle1.getText() + "是否正确",
                                            BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                                }
                            }
                        }
                    } else {
                        rvInputDataList1.setVisibility(View.GONE);
                        materialinfoBeanList1.clear();
                        eqpThingListAdapter1.notifyDataSetChanged();
                        ToastUtils.showFreeToast("物料条码" + tvTitle1.getText() + "扫描信息有误", BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        etInput2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                return event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER);
            }
        });

        etInput2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    if (s.length() > 0) {
                        //扫描到数据 然后请求接口
                        isAllow2 = isAllow(s.toString(), 2);
                        if (type2.equals("HubBlade") || type2.equals("HubBladeYZ1") || type2.equals("HubBladeYZ2")) {
                            if (!isYingYuan2) {
                                if (isAllow2) {
                                    materialinfoBeanList2.clear();
                                    materialinfoBeanList2.add(bean2);
                                    eqpThingListAdapter2.notifyDataSetChanged();
                                    requestSubmit("check", 2);
                                    rvInputDataList2.setVisibility(View.VISIBLE);
                                } else {
                                    materialinfoBeanList2.clear();
                                    eqpThingListAdapter2.notifyDataSetChanged();
                                    rvInputDataList2.setVisibility(View.GONE);
                                    ToastUtils.showFreeToast("请检查扫描的物料条码" + tvTitle2.getText() + "是否正确",
                                            BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                                }
                            }
                        }
                    } else {
                        rvInputDataList2.setVisibility(View.GONE);
                        materialinfoBeanList2.clear();
                        eqpThingListAdapter2.notifyDataSetChanged();
                        ToastUtils.showFreeToast("物料条码" + tvTitle2.getText() + "扫描信息有误", BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
    private void requestSubmit(final String submitType, final int who) {
        if (submitType.equals("change") && who == 1) {
            successCount = 0;
        }
        MaterialInfoBean submitBean = who == 1 ? bean1 : bean2;
        List<InputDataEntity.InputObject> submitInputList = who == 1 ? inputList1 : inputList2;
        EntityCallBack<BaseEntity<Object>> callBack = new DialogEntityCallBack<BaseEntity<Object>>
                (new TypeToken<BaseEntity<Object>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess
                    (final Response<BaseEntity<Object>> response) {
                if (response.body().isSuccess(BothThingChangeActivity.this)) {
                    if (submitType.equals("change")) {
                        successCount += 1;
                        if (successCount == 2) {
                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    BothThingChangeActivity.this.finish();
                                }
                            }, 1000);
                            loadSuccess(response.body().getMessage());
                        }
                    } else {
                        if (who == 1) {
                            etInput2.requestFocus();
                            isAllow1 = true;
                        } else {
                            isAllow2 = true;
                        }
                        loadSuccess(response.body().getMessage());
                    }
                } else {
                    loadFail(response.body().getMessage());
                    if (submitType.equals("check")) {
                        if (who == 1) {
                            isAllow1 = false;
                            materialinfoBeanList1.clear();
                            rvInputDataList1.setVisibility(View.GONE);
                            eqpThingListAdapter1.notifyDataSetChanged();
                        } else {
                            isAllow2 = false;
                            materialinfoBeanList2.clear();
                            rvInputDataList2.setVisibility(View.GONE);
                            eqpThingListAdapter2.notifyDataSetChanged();
                        }

                    }
                }
            }

            @Override
            public void onError
                    (Response<BaseEntity<Object>> response) {
                super.onError(response);
                loadError(response.getException(), "ChangeMeterial");
            }
        };
        numIs++;
        Map<String, String> map = new HashMap<>();
        map.put("EqpId", getEqpID());
        map.put("OPID", StaticMembers.CUR_USER.getUSERNAME());
        map.put("Name", StaticMembers.CUR_USER.getUSERNAME());
        map.put("Type", submitBean.getType());
        map.put("Size", submitBean.getSize());
        map.put("RemainTime", submitBean.getRemainTime());
        map.put("SeqNo", submitBean.getSeqNo());
        map.put("MaterialPartNo", submitBean.getMaterialPartNo());
        map.put("Device", submitBean.getDevice());
        map.put("WaferSource", submitBean.getWaferSource());
        map.put("Diagram", submitBean.getDiagram());
        map.put("ThawEndTime", submitBean.getThawEndTime());
        map.put("SawLength", submitBean.getSawLength());
        map.put("SawThickness", submitBean.getSawThickness());
        map.put("ExternalDiameter", submitBean.getExternalDiameter());
        map.put("InternalDiameter", submitBean.getInternalDiameter());
        map.put("MaterialLotNo", submitBean.getMaterialLotNo());
        map.put("EndTime", submitBean.getEndTime());
        map.put("StartTime", submitBean.getStartTime());
        map.put("ChangeMeterialType", submitType);
        /*2020-1-9 Start 双刀，单到*/
        map.put("ChaegeMTwo","Two");
        map.put("numIs",numIs+"");
        /*2020-1-9 End 双刀，单到*/
        if (submitType.equals("change")) {
            JSONObject jsonObject = new JSONObject();
            try {
                if (submitInputList.size() == 0) {
                    jsonObject.put("INPUTDATA", "");
                } else {
                    JSONArray jsonArray = new JSONArray(new Gson().toJson(submitInputList));
                    jsonObject.put("INPUTDATA", jsonArray);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            map.put("InputDataList", jsonObject.toString());
        }
        NetUtils.requestNet(this, "/ChangeMeterial", map, callBack);
    }

    public boolean isAllow(String str, int who1) {
        if (who1 == 1) {
            isYingYuan1 = false;
            String[] strs;
            if (str.contains(";")) {
                strs = str.split(";");
            } else {
                strs = new String[1];
                strs[0] = str;
            }
         /*   if (strs.length == 4) {
                bean1.setMaterialPartNo(strs[0]);
                bean1.setSawLength(strs[1]);
                bean1.setSawThickness(strs[2]);
                bean1.setSeqNo(strs[3]);
                return true;
            }
            else*/
            if (strs.length == 5) {
                bean1.setMaterialPartNo(strs[0]);
                bean1.setSawLength(strs[1]);
                bean1.setSawThickness(strs[2]);
                bean1.setSeqNo(strs[4]);
                return true;
            } else if (strs.length == 1 && str.length() > 15) {
                if (str.substring(str.length() - 15, str.length() - 14).equals("H")) {
                    isYingYuan1 = true;
                    str = str.substring(str.length() - 15, str.length() - 3);
                    requestHubBlade(str, 1);
                    return true;
                } else if (str.substring(str.length() - 16, str.length() - 15).equals("H")) {
                    isYingYuan1 = true;
                    str = str.substring(0, str.length() - 1);
                    str = str.substring(str.length() - 15, str.length() - 3);
                    requestHubBlade(str, 1);
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            isYingYuan2 = false;
            String[] strs;
            if (str.contains(";")) {
                strs = str.split(";");
            } else {
                strs = new String[1];
                strs[0] = str;
            }
           /* if (strs.length == 4) {
                bean2.setMaterialPartNo(strs[0]);
                bean2.setSawLength(strs[1]);
                bean2.setSawThickness(strs[2]);
                bean2.setSeqNo(strs[3]);
                return true;
            }
            else*/
            if (strs.length == 5) {
                bean2.setMaterialPartNo(strs[0]);
                bean2.setSawLength(strs[1]);
                bean2.setSawThickness(strs[2]);
                bean2.setSeqNo(strs[4]);
                return true;
            } else if (strs.length == 1 && str.length() > 15) {
                if (str.substring(str.length() - 15, str.length() - 14).equals("H")) {
                    isYingYuan2 = true;
                    str = str.substring(str.length() - 15, str.length() - 3);
                    requestHubBlade(str, 2);
                    return true;
                } else if (str.substring(str.length() - 16, str.length() - 15).equals("H")) {
                    isYingYuan2 = true;
                    str = str.substring(0, str.length() - 1);
                    str = str.substring(str.length() - 15, str.length() - 3);
                    requestHubBlade(str, 2);
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }


    private void requestHubBlade(String str, final int who) {
        EntityCallBack<BaseEntity<WaferSawEntity>> callBack = new DialogEntityCallBack<BaseEntity<WaferSawEntity>>
                (new TypeToken<BaseEntity<WaferSawEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess
                    (final Response<BaseEntity<WaferSawEntity>> response) {

                if (response.body().isSuccess(BothThingChangeActivity.this)) {
                    if (who == 1) {
                        isAllow1 = true;
                        bean1.setMaterialPartNo(response.body().getData().getMATERIALPARTNO());
                        bean1.setSawLength(response.body().getData().getSAWLENGTH());
                        bean1.setSawThickness(response.body().getData().getSAWTHICKNESS());
                        bean1.setSeqNo(response.body().getData().getSEQNO());
                        bean1.setInternalDiameter(response.body().getData().getINTERNALDIAMETER());
                        bean1.setExternalDiameter(response.body().getData().getEXTERNALDIAMETER());
                        if (isAllow1) {
                            materialinfoBeanList1.clear();
                            materialinfoBeanList1.add(bean1);
                            eqpThingListAdapter1.notifyDataSetChanged();
                            requestSubmit("check", 1);
                            rvInputDataList1.setVisibility(View.VISIBLE);
                        } else {
                            materialinfoBeanList1.clear();
                            rvInputDataList1.setVisibility(View.GONE);
                            eqpThingListAdapter1.notifyDataSetChanged();
                            ToastUtils.showFreeToast("请检查扫描的物料条码" + tvTitle1.getText() + "是否正确",
                                    BothThingChangeActivity.this, false, Toast.LENGTH_SHORT);
                        }
                    } else {
                        isAllow2 = true;
                        bean2.setMaterialPartNo(response.body().getData().getMATERIALPARTNO());
                        bean2.setSawLength(response.body().getData().getSAWLENGTH());
                        bean2.setSawThickness(response.body().getData().getSAWTHICKNESS());
                        bean2.setSeqNo(response.body().getData().getSEQNO());
                        bean2.setInternalDiameter(response.body().getData().getINTERNALDIAMETER());
                        bean2.setExternalDiameter(response.body().getData().getEXTERNALDIAMETER());
                        if (isAllow2) {
                            materialinfoBeanList2.clear();
                            materialinfoBeanList2.add(bean2);
                            eqpThingListAdapter2.notifyDataSetChanged();
                            requestSubmit("check", 2);
                            rvInputDataList2.setVisibility(View.VISIBLE);
                        } else {
                            materialinfoBeanList2.clear();
                            rvInputDataList2.setVisibility(View.GONE);
                            eqpThingListAdapter2.notifyDataSetChanged();
                            ToastUtils.showFreeToast("请检查扫描的物料条码是否正确",
                                    BothThingChangeActivity.this, false, Toast.LENGTH_LONG);
                        }
                    }

                } else {
                    if (who == 1) {
                        materialinfoBeanList1.clear();
                        eqpThingListAdapter1.notifyDataSetChanged();
                        isAllow1 = false;
                    } else {
                        materialinfoBeanList2.clear();
                        eqpThingListAdapter2.notifyDataSetChanged();
                        isAllow2 = false;
                    }
                    loadFail(response.body().getMessage());
                }
            }

            @Override
            public void onError
                    (Response<BaseEntity<WaferSawEntity>> response) {
                super.onError(response);
                if (who == 1) {
                    isAllow1 = false;
                } else {
                    isAllow2 = false;
                }
                loadError(response.getException(), "WaferSaw");
            }
        };

        Map<String, String> map = new HashMap<>();
        map.put("SeqNo", str);
        map.put("Materialtype", "HubBlade");
        NetUtils.requestNet(this, "/WaferSaw", map, callBack);
    }

    @Override
    protected void initData() {
        numIs= Integer.parseInt(getIntent().getStringExtra("numIs"));
        requestInputData(1);
        requestInputData(2);
        materialinfoBeanList1 = new ArrayList<>();
        eqpThingListAdapter1 = new EqpThingListAdapter(materialinfoBeanList1, null);
        eqpThingListAdapter1.setIsShowButton(false);
        eqpThingListAdapter1.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        eqpThingListAdapter1.isFirstOnly(true);
        rvEqpList1.setAdapter(eqpThingListAdapter1);
        materialinfoBeanList2 = new ArrayList<>();
        eqpThingListAdapter2 = new EqpThingListAdapter(materialinfoBeanList2, null);
        eqpThingListAdapter2.setIsShowButton(false);
        eqpThingListAdapter2.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        eqpThingListAdapter2.isFirstOnly(true);
        rvEqpList2.setAdapter(eqpThingListAdapter2);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
    }

    private void requestInputData(final int who) {
        EntityCallBack<BaseEntity<ChangeThingInputDataEntity>> callBack = new DialogEntityCallBack<BaseEntity<ChangeThingInputDataEntity>>
                (new TypeToken<BaseEntity<ChangeThingInputDataEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess
                    (final Response<BaseEntity<ChangeThingInputDataEntity>> response) {
                if (response.body().isSuccess(BothThingChangeActivity.this)) {
                    if (who == 1) {
                        dealInputList(response.body().getData().getINPUTDATALIST().getINPUTDATA(), 1);
                        InputDataListAdapter inputDataListAdapter = new InputDataListAdapter(inputList1);
                        inputDataListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
                        inputDataListAdapter.isFirstOnly(true);
                        rvInputDataList1.setAdapter(inputDataListAdapter);
                    } else {
                        dealInputList(response.body().getData().getINPUTDATALIST().getINPUTDATA(), 2);
                        InputDataListAdapter inputDataListAdapter = new InputDataListAdapter(inputList2);
                        inputDataListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
                        inputDataListAdapter.isFirstOnly(true);
                        rvInputDataList2.setAdapter(inputDataListAdapter);
                    }
                } else {
                    loadFail(response.body().getMessage());
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            BothThingChangeActivity.this.finish();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onError
                    (Response<BaseEntity<ChangeThingInputDataEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "ShowMeterialInputData");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        BothThingChangeActivity.this.finish();
                    }
                }, 2000);
            }
        };

        Map<String, String> map = new HashMap<>();
        map.put("EqpId", getEqpID());
        map.put("USERNAME", StaticMembers.CUR_USER.getUSERNAME());
        map.put("Type", who == 1 ? type1 : type2);
        NetUtils.requestNet(this, "/ShowMeterialInputData", map, callBack);
    }

    private void dealInputList(List<InputDataEntity.InputObject> inputdata, int who) {
        if (who == 1) {
            inputList1 = new ArrayList<>();
            if (StaticMembers.isOffLine) {
                inputList1.addAll(inputdata);
            } else {
                List<InputDataEntity.InputObject> removeList = new ArrayList<>();
                for (InputDataEntity.InputObject object : inputdata) {
                    if (object.getEQPModeType().equals("Y")) {
                        removeList.add(object);
                    }
                }
                inputdata.removeAll(removeList);
                inputList1.addAll(inputdata);
            }
        } else if (who == 2) {
            inputList2 = new ArrayList<>();
            if (StaticMembers.isOffLine) {
                inputList2.addAll(inputdata);
            } else {
                List<InputDataEntity.InputObject> removeList = new ArrayList<>();
                for (InputDataEntity.InputObject object : inputdata) {
                    if (object.getEQPModeType().equals("Y")) {
                        removeList.add(object);
                    }
                }
                inputdata.removeAll(removeList);
                inputList2.addAll(inputdata);
            }
        }

    }
}
